(function(){
	var shift=false;
	var ctrl=false;
	var alt=false;
	var knownkeys={27:'esc',32:'space',112:'f1',113:'f2',114:'f3',115:'f4',116:'f5',117:'f6',118:'f7',119:'f8',120:'f9',121:'f10',122:'f11',123:'f12',19:'break',192:'tilde',189:'minus',187:'plus',8:'backspace',9:'tab',
					20:'caps',219:'[',221:']',13:'enter',186:'colon',222:'quote',220:'pipe',188:'comma',190:'period',191:'question'};
	$(document).bind('keydown',function(evt){
		if(evt.which==16){shift=true;return;}
		if(evt.which==17){ctrl=true;return;}
		if(evt.which==18){alt=true; return;}
		var key=[];
		if(ctrl)key.push('ctrl');
		if(alt)key.push('alt');
		if(shift)key.push('shift');
		if(typeof(knownkeys[evt.which])!='undefined'){
			key.push(knownkeys[evt.which]);
		}else{
			key.push(String.fromCharCode(evt.which));
		}
		key=key.join('.');
		var keymap=keys.getActiveMap();
		if(typeof(keymap[key])=='function'){
			keymap[key](evt);
			return false;
		}
		//chrome.extension.sendRequest({action:'keypress', key:key}, function(response){console.log(response);});
		//return false;
	}).bind('keyup',function(evt){
		if(evt.which==16){shift=false;return;}
		if(evt.which==17){ctrl=false;return;}
		if(evt.which==18){alt=false;return;}
	});
})();